<template>
  <body class="login_bg">
  <section class="loginBox">
    <header class="loginHeader">
      <h1>超市订单管理系统</h1>
    </header>
    <section class="loginCont">
      <form class="loginForm" name="actionForm" id="actionForm" method="post">
        <div class="info"></div>
        <div class="inputbox">
          <label for="user">用户名：</label>
          <input type="text" class="input-text" id="userCode" v-model="user.userCode" name="userCode"
                 placeholder="请输入用户名" required/>
        </div>
        <div class="inputbox">
          <label for="mima">密码：</label>
          <input type="password" id="userPassword" v-model="user.password" name="userPassword" placeholder="请输入密码"
                 required/>
        </div>
        <div class="subBtn">

          <input type="button" value="登录" @click="login"/>
          <input type="reset" value="重置"/>
        </div>
      </form>
    </section>
  </section>
  </body>
</template>

<script>
import axios from "axios";

export default {
  name: "Login",
  data() {
    return {
      user: {
        userCode: '',
        password: ''
      }
    }
  },
  methods: {
    login() {
      let _this = this
      /*console.log(8888)
      let _this = this
      let data = new URLSearchParams()
      data.append('name', _this.user.userCode)
      data.append('pass', _this.user.password)
      console.log(data)
      axios({
        method: 'post',
        uri: '/api/smbms-login/login',
        data: data
      }).then((response) => {
        /!*if (response.data.success) {
          let token = response.data.data
          window.localStorage.setItem('token', token)
          _this.$router.push('/')
        } else {
          _this.$message.error(response.data.errorMsg);
        }*!/
        console.log(response)
      }).catch(()=>{
        console.log('error')
      })*/
      axios.get('/api/smbms-login/login', {
        params: {
          name: _this.user.userCode,
          pass: _this.user.password
        }
      }).then((response)=>{
        if (response.data.success) {
          let token = response.data.data
          window.localStorage.setItem('token', token)
          window.localStorage.setItem('nickName',response.data.errorMsg)
          _this.$router.push('/')
        } else {
          _this.$message.error(response.data.errorMsg);
        }
      })
    }
  }
}
</script>

<style lang="css">
@import url('../assets/css/style.css');
</style>